var utils = require('./exports/utils')
var constant = require('./exports/constant')
var point_map = require('./exports/point_map')
var ad_util = require('./exports/ad_util')
//我的 -> 邀请好友 -> 开福袋
var bless = {
  go_page_from_home() {},
  start() {
    var ui_text = utils.click_text("开福袋");
    if (ui_text) {
      console.log("bless start: 找到【开福袋】");
      sleep(constant.min_click_after_time * 1000);
      this.init();
    } else {
      console.log("bless start: 没找到【开福袋】");
    }
  },
  init() {
    var ui_text =
      utils.exists_text_starts_with("再看一个领取") ||
      utils.exists_text_starts_with("观看视频再得") ||
      utils.exists_text_starts_with("看广告再") ||
      utils.exists_text_starts_with("看视频再领");
    if (ui_text) {
      console.log(
        "bless init: 找到【再看一个领取】或【观看视频再得】或【看广告再】或【看视频再领】" +
          ui_text.text()
      );
      var gold = utils.get_gold(ui_text.text());
      console.log("bless init: " + gold + "金币");
      if (gold > constant.min_gold) {
        if (utils.click_text_starts_with("再看一个领取")) {
        }
        if (utils.click_text_starts_with("观看视频再得")) {
        }
        if (utils.click_text_starts_with("看广告再")) {
        }
        if (utils.click_text_starts_with("看视频再领")) {
        }
        sleep(constant.min_click_after_time * 1000);
        ad_util.execute();
        this.next();
      } else {
        utils.click_point.apply(
          utils,
          utils.get_size_point(point_map["开福袋之后的关闭"])
        );
        sleep(constant.min_click_after_time * 1000);
        this.next();
      }
    } else {
      console.log(
        "bless init: 没找到【再看一个领取】或【观看视频再得】或【看广告再】"
      );
      this.next();
    }
  },
  next() {
    console.log("bless next");
    if (utils.exists_text_starts_with("看广告再")) {
      console.log("bless next: 找到【看广告再】");
      this.init();
      return;
    }
    if (utils.click_text("开心收下")) {
      console.log("bless next: 找到【开心收下】");
      sleep(constant.min_click_after_time * 1000);
    }
    if (utils.click_text("立即收下")) {
      console.log("bless next: 找到【立即收下】");
      sleep(constant.min_click_after_time * 1000);
    }
  },
};

module.exports = bless